home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 1.toast / pc / sample code / contributed / waste / extras / unsupported / weextras.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  3.6 KB  |  172 lines

  1. /*
  2.  *    WEExtras.c
  3.  *
  4.  *    Routines for installing and removing various hooks
  5.  *
  6.  *    Written by Jonathan Kew
  7.  *
  8.  */
  9.  
  10. #include "WEExtras.h"
  11.  
  12. // prototypes for the hook routines defined in WEExtraHooks.c
  13.  
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17.  
  18. extern pascal void _WEShowInvisiblesDrawText(Ptr, long, Fixed, JustStyleCode, WEReference);
  19. extern pascal StyledLineBreakCode _WENoWrapLineBreak(Ptr, long, long, long,
  20.                     Fixed *, long *, WEReference);
  21.  
  22. #ifdef __cplusplus
  23. }
  24. #endif
  25.  
  26. /* user tags for invisibles color*/
  27. enum
  28. {
  29.     kInvisiblesOldDrawTextProcTag    =    'icDT' ,
  30.     kInvisiblesColorRedGreenTag     =    'icRG' ,
  31.     kInvisiblesColorBlueTag            =    'icB_'
  32. } ;
  33.  
  34. // static UPP's
  35. static WELineBreakUPP        _weNoWrapLineBreakProc = nil;
  36. static WEDrawTextUPP        _weShowInvisiblesDrawTextProc = nil;
  37.  
  38. pascal OSErr WEInstallCrOnlyHook(WEReference we)
  39. {
  40.     OSErr err;
  41.  
  42.     // if first time, create routine descriptor
  43.     if (_weNoWrapLineBreakProc == nil)
  44.     {
  45.         _weNoWrapLineBreakProc = NewWELineBreakProc(_WENoWrapLineBreak);
  46.     }
  47.  
  48.     err = WESetInfo( weLineBreakHook, &_weNoWrapLineBreakProc, we );
  49.  
  50.     return err;
  51. }
  52.  
  53. pascal OSErr WERemoveCrOnlyHook( WEReference we )
  54. {
  55.     UniversalProcPtr hook = nil;
  56.     OSErr err;
  57.  
  58.     err = WESetInfo( weLineBreakHook, &hook, we );
  59.  
  60.     return err;
  61. }
  62.  
  63. pascal Boolean WEIsCrOnly( WEReference we )
  64. {
  65.     WELineBreakUPP hook = nil;
  66.  
  67.     // return true if our no-wrap hook is installed
  68.  
  69.     return     ( _weNoWrapLineBreakProc != nil ) &&
  70.             ( WEGetInfo( weLineBreakHook, &hook, we ) == noErr) &&
  71.             ( _weNoWrapLineBreakProc == hook );
  72. }
  73.  
  74. pascal OSErr WEInstallShowInvisiblesHook ( WEReference we )
  75. {
  76.     WEDrawTextUPP drawTextProc = nil ;
  77.     OSErr err;
  78.  
  79.     //    if first time, create routine descriptor
  80.     if ( _weShowInvisiblesDrawTextProc == nil )
  81.     {
  82.         _weShowInvisiblesDrawTextProc = NewWEDrawTextProc ( _WEShowInvisiblesDrawText ) ;
  83.     }
  84.  
  85.     //    get current text drawing hook
  86.     if ( ( err = WEGetInfo ( weDrawTextHook, & drawTextProc, we ) ) != noErr )
  87.     {
  88.         return err ;
  89.     }
  90.  
  91.     //    save it back in the same instance as user data
  92.     if ( ( err = WESetUserInfo ( kInvisiblesOldDrawTextProcTag, ( SInt32 ) drawTextProc, we ) ) != noErr )
  93.     {
  94.         return err ;
  95.     }
  96.  
  97.     //    replace the old text drawing hook with our show invisibles function
  98.     return WESetInfo ( weDrawTextHook, & _weShowInvisiblesDrawTextProc, we ) ;
  99. }
  100.  
  101. pascal OSErr WERemoveShowInvisiblesHook ( WEReference we )
  102. {
  103.     WEDrawTextUPP drawTextProc = nil ;
  104.     OSErr err;
  105.  
  106.     //    retrieve the original text drawing hook
  107.     if ( ( err = WEGetUserInfo ( kInvisiblesOldDrawTextProcTag, ( SInt32 * ) & drawTextProc, we ) ) != noErr )
  108.     {
  109.         return err ;
  110.     }
  111.  
  112.     //    put it back in place
  113.     return WESetInfo ( weDrawTextHook, & drawTextProc, we ) ;
  114. }
  115.  
  116. pascal Boolean WEIsShowInvisibles( WEReference we )
  117. {
  118.     WEDrawTextUPP hook = nil;
  119.  
  120.     // return true if our no-wrap hook is installed
  121.  
  122.     return     ( _weShowInvisiblesDrawTextProc != nil ) &&
  123.             ( WEGetInfo( weDrawTextHook, &hook, we ) == noErr) &&
  124.             ( _weShowInvisiblesDrawTextProc == hook );
  125. }
  126.  
  127. pascal OSErr WESetInvisiblesColor( const RGBColor *color, WEReference we )
  128. {
  129.     OSErr err ;
  130.  
  131.     if ( we == nil )
  132.     {
  133.         return nilHandleErr ;
  134.     }
  135.  
  136.     if ( ( err = WESetUserInfo ( kInvisiblesColorRedGreenTag, * ( SInt32 * ) color, we ) ) != noErr )
  137.     {
  138.         return err ;
  139.     }
  140.  
  141.     if ( ( err = WESetUserInfo ( kInvisiblesColorBlueTag, color -> blue, we ) ) != noErr )
  142.     {
  143.         return err ;
  144.     }
  145.  
  146.     return noErr ;
  147. }
  148.  
  149. pascal OSErr WEGetInvisiblesColor( RGBColor *color, WEReference we )
  150. {
  151.     SInt32 tmp ;
  152.     OSErr err ;
  153.  
  154.     if ( we == nil )
  155.     {
  156.         return nilHandleErr ;
  157.     }
  158.  
  159.     if ( ( err = WEGetUserInfo ( kInvisiblesColorRedGreenTag, ( SInt32 * ) color, we ) ) != noErr )
  160.     {
  161.         return err ;
  162.     }
  163.  
  164.     if ( ( err = WEGetUserInfo ( kInvisiblesColorBlueTag, & tmp, we ) ) != noErr )
  165.     {
  166.         return err ;
  167.     }
  168.  
  169.     color -> blue = tmp ;
  170.     return noErr ;
  171. }
  172.